package my.study.c.consul.consumer.app.configuration;

import lombok.extern.slf4j.Slf4j;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

@Slf4j
public class ResponseInterceptor implements Interceptor {

    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request request = chain.request();
        try {
            Response response = chain.proceed(request);
            log.info("okhttp3.Protocol: {}", response.protocol());
            return response;
        } catch (Exception e) {
            log.error("exception: ", e);
            throw e;
        }
    }
}